package dao

import (
	"go.uber.org/zap"
	"smart-health-platforms/pkg"
	"user_srv/model"
)

func AddressDel(AddressId int) error {
	var address model.Address
	address.Id = int32(AddressId)
	if err := address.DelAddress(); err != nil {
		pkg.Error("删除失败", zap.Error(err))
		return err
	}
	return nil
}

func AddressList(userId int) (add []model.Address, err error) {
	var address model.Address
	address.UserId = int32(userId)
	listAddress, err := address.ListAddress()
	if err != nil {
		pkg.Error("列表失败", zap.Error(err))
		return nil, err
	}
	return listAddress, nil
}
func AddressAdd(userId int32, Address string) error {
	var user model.Users
	user.Id = uint(uint64(userId))
	if err := user.GetUserInfoById(int(userId)); err != nil {
		pkg.Error("查询失败", zap.Error(err))
		return err
	}
	var address model.Address
	address = model.Address{
		UserId:  userId,
		Address: Address,
		Name:    user.NickName,
		Mobile:  user.Mobile,
	}
	err := address.AddAddressWithDefault(userId)
	if err != nil {
		pkg.Error("添加失败", zap.Error(err))
		return err
	}
	return nil
}
